<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="主题名称">
          <el-input v-model="dataForm.name" placeholder="主题名称" clearable></el-input>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :custom="{immediate:true}">
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('cpn:cpnTheme:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
          <el-button v-if="$hasPermission('cpn:cpnTheme:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
        <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize :sort-config="{trigger:'cell'}" @sort-change="sortChange" @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex" :data="dataList" max-height="auto">
          <vxe-table-column type="index" align="center" width="60"></vxe-table-column>
          <vxe-table-column field="name" title="主题名称">
            <template slot-scope="scope">
              <el-button type="text" @click="openData(scope.row)"> {{scope.row.name}}
              </el-button>
            </template>
          </vxe-table-column>
          <vxe-table-column field="comparisonDate" title="上次比对时间" width="160">
          </vxe-table-column>
          <vxe-table-column title="handle" width="200" show-overflow="false" align="center">
            <template slot-scope="scope">
              <!-- @click="addOrUpdateHandle(scope.row)" -->
              <el-button type="text" size="small" icon="el-icon-c-scale-to-original">列定义</el-button>
              <el-button type="text" size="small" icon="el-icon-monitor">规则</el-button>
              <el-button type="text" size="small" icon="el-icon-document" @click="openData(scope.row)">比对</el-button>

              <!-- <el-button v-if="$hasPermission('cpn:cpnTheme:update')" type="text" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button> -->
              <!-- <el-button v-if="$hasPermission('cpn:cpnTheme:delete')" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button> -->
            </template>
          </vxe-table-column>
        </vxe-table>
        <el-pagination :current-page="page" :page-sizes="pageSizes" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
      </div>
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './cpnTheme-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/cpn/cpnTheme/page',
        getDataListIsPage: true,
        deleteURL: '/cpn/cpnTheme',
        deleteIsBatch: true,
        exportURL: '/cpn/cpnTheme/export'
      },
      headLock: false,
      dataForm: {
        name: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    },
    // 新增 / 修改
    openData (row) {
      var title = '比对配置' + '-' + row.name
      var id
      if (row && row.id) {
        // title = '编辑代码模板--' + row.templateName + '(' + row.templateCode + ')'
        id = row.id
      }
      // 打开路由
      var router = {
        name: 'cpn-cpnTheme-editTab',
        id: id,
        menuId: this.$route.meta.menuId,
        oldName: 'cpn-cpnTheme',
        path: 'cpn/cpnData',
        title: title
      }
      var params = {
        themeId: id,
        name: row.name,
        timestamp: this.$xeutils.timestamp()
      }
      this.$options.methods.openNewTab(this.$router, router, params)
    }
  }
}
</script>
